
#pragma once

#include "base_types.h"
#include "BaseTypesWrappers.h"
#include "HelperFunctions.h"

using namespace System;
using namespace System::Globalization;
using namespace System::ComponentModel;

ref struct BridgeId;

// ============================================================================

ref class UInt32HexTypeConverter : public TypeConverter
{
public:
	virtual bool CanConvertFrom (ITypeDescriptorContext^ context, Type^ sourceType) override;
	virtual bool CanConvertTo (ITypeDescriptorContext^ context, Type^ destinationType) override;
	virtual Object^ ConvertTo (ITypeDescriptorContext^ context, CultureInfo^ culture, Object^ value, Type^ destinationType) override;
	virtual Object^ ConvertFrom (ITypeDescriptorContext^ context, CultureInfo^ culture, Object^ value) override;
};

// ============================================================================

ref class UInt16HexTypeConverter : public TypeConverter
{
public:
	virtual bool CanConvertFrom (ITypeDescriptorContext^ context, Type^ sourceType) override;
	virtual bool CanConvertTo (ITypeDescriptorContext^ context, Type^ destinationType) override;
	virtual Object^ ConvertTo (ITypeDescriptorContext^ context, CultureInfo^ culture, Object^ value, Type^ destinationType) override;
	virtual Object^ ConvertFrom (ITypeDescriptorContext^ context, CultureInfo^ culture, Object^ value) override;
};

// ============================================================================

ref class UInt8HexTypeConverter : public TypeConverter
{
public:
	virtual bool CanConvertFrom (ITypeDescriptorContext^ context, Type^ sourceType) override;
	virtual bool CanConvertTo (ITypeDescriptorContext^ context, Type^ destinationType) override;
	virtual Object^ ConvertTo (ITypeDescriptorContext^ context, CultureInfo^ culture, Object^ value, Type^ destinationType) override;
	virtual Object^ ConvertFrom (ITypeDescriptorContext^ context, CultureInfo^ culture, Object^ value) override;
};

// ============================================================================

ref class BridgeIdConverter : ExpandableObjectConverter
{
public:
	virtual bool CanConvertTo (ITypeDescriptorContext^ context, Type^ destinationType) override;
	virtual Object^ ConvertTo (ITypeDescriptorContext^ context, CultureInfo^ culture, Object^ value, Type^ destinationType) override;
};

// ============================================================================

[TypeConverter (BridgeIdConverter::typeid)]
ref struct BridgeId
{
	const BRIDGE_ID* bridgeId;

	BridgeId (const BRIDGE_ID* bridgeId)
	{
		this->bridgeId = bridgeId;
	}

	[TypeConverter (UInt16HexTypeConverter::typeid)]
	property unsigned short priority { unsigned short get () { return this->bridgeId->_priority.GetValue (); } }

	property String^ address { String^ get () { return BRIDGE_ADDRESS_ToString (&bridgeId->_address); } }
};

// ============================================================================

[TypeConverter (ExpandableObjectConverter::typeid)]
ref struct PriorityVectorWrapper
{
	const PRIORITY_VECTOR_SHORT* pvs;

	PriorityVectorWrapper (const PRIORITY_VECTOR_SHORT* pvs)
	{
		this->pvs = pvs;
	}

	property BridgeId^		a_RootId {BridgeId^ get () {return gcnew BridgeId (&pvs->RootId); }}

	property unsigned long	b_ExternalRootPathCost {unsigned long get () { return pvs->ExternalRootPathCost.GetValue (); }}

	property BridgeId^		c_RegionalRootId {BridgeId^ get () { return gcnew BridgeId (&pvs->RootId); } }

	property unsigned long	d_InternalRootPathCost { unsigned long get () { return pvs->InternalRootPathCost.GetValue (); } }

	property BridgeId^		e_DesignatedBridgeId {BridgeId^ get () { return gcnew BridgeId (&pvs->RootId); } }

	[TypeConverter (UInt16HexTypeConverter::typeid)]
	property unsigned short	f_DesignatedPortId { unsigned short get () { return pvs->DesignatedPortId.GetValue (); } }

};

// ============================================================================
